<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <p>
        <input type="text" name="" id="username">
    </p>
    <p>
        <input type="text" name="" id="age">
    </p>
    <p>
        <input type="button" name="" value="提交" id="btn">
    </p>
    <script>
        var btn = document.querySelector('#btn');
        var username = document.querySelector('#username');
        var age = document.querySelector('#age');
        btn.onclick = function () {
            var xhr = new XMLHttpRequest();

            var nameValue = username.value;
            var ageValue = age.value;
            var params = 'username='+nameValue+'&age='+ageValue;
            xhr.open('get','http://localhost:3000/get?'+params);
            xhr.send()
            xhr.onload = function () {
                console.log(JSON.parse(xhr.responseText));
            }
        }
    </script>
</body>
</html>